package com.nleaves.baiduloc.citylist.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nleaves.baiduloc.activity.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/11/19.
 */
public class AddressAdapter extends ArrayAdapter {

    ArrayList<String> arrayList;
    LayoutInflater inflater;

    public AddressAdapter(Context context, int resource) {
        super(context, resource);
        inflater = LayoutInflater.from(context);
        arrayList = new ArrayList<>();
    }

    public AddressAdapter(Context context, int resource, int textViewResourceId) {
        super(context, resource, textViewResourceId);
    }

    public AddressAdapter(Context context, int resource, Object[] objects) {
        super(context, resource, objects);
    }

    public AddressAdapter(Context context, int resource, int textViewResourceId, Object[] objects) {
        super(context, resource, textViewResourceId, objects);
    }

    public AddressAdapter(Context context, int resource, List objects) {
        super(context, resource, objects);
    }


    public AddressAdapter(Context context, int resource, int textViewResourceId, List objects) {
        super(context, resource, textViewResourceId, objects);
    }

//    public AddressAdapter(Context context, ArrayList<String> arrayList) {
//        arrayList = new ArrayList<>();
//        inflater = LayoutInflater.from(context);
//    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return arrayList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            inflater.inflate(R.layout.address_item, null);
            viewHolder = new ViewHolder();
            viewHolder.textView = (TextView) convertView.findViewById(R.id.myaddress);
            viewHolder.imageView = (ImageView) convertView.findViewById(R.id.add);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.textView.setText(arrayList.get(position));
        viewHolder.imageView.setImageResource(R.drawable.add);
        return convertView;
    }

    private class ViewHolder {
        private TextView textView;
        private ImageView imageView;
    }
}
